#!/usr/bin/python3

from baseSql import *
from dbPool import *

class CCustomerMgr:
    tableTitle = ["所有客户"]
    def __init__(self, log):
        self.log=log
        self.customerList=[self.tableTitle]

    def init(self, db):
        self.db = db
        self.reload()


    def reload(self):
        self.customerList=[self.tableTitle]
        self.db.query("select customer from " + t_customer_info)
        rows = self.db.getData()
        for row in rows:
            self.customerList.append(row[0])
        self.log.log("load customer list data finish")

    def add(self, user, customerName, customerType, note = ""):
        sql = "insert into "+ t_customer_info + " (customer, customer_type, note) values( " + \
              "'" +customerName + "','" + customerType + "'," + note + ")"
        execDBData(user=user, msg="add customer", doSql=sql, dbConnPool=self.db)

    def delete(self, user, customerName, note):
        sql = "delete from "+t_customer_info + " where customer_name = '"+ customerName + "'"
        execDBData(user=user, msg="del customer", doSql=sql, dbConnPool=self.db)

